package com.javademo;

import lombok.extern.slf4j.Slf4j;

import java.util.Arrays;
import java.util.Formatter;
import java.util.Scanner;

@Slf4j
public class ForEachTest {
    public static void main(String[] args) {
        varargsTest(23,4,6,6,2,2,5,6,7,3,4,65,6,3);
    }

    private static void inputIntTest(){
        Scanner scanner = new Scanner(System.in);
        scanner.next();
        scanner.nextInt();
        scanner.findInLine("\\d+");
    }

    private static void copyArrayTest(int[] arr1, int[] arr2){
        log.info("复制数组中...");
        log.info("复制完成！");
        System.arraycopy(arr1, 0, arr2, 0, arr1.length);
    }

    private static void formatTest(){
        String str = String.format("%d %s %f", 1, "hello", 3.14);
        log.info(str);
    }

    private static void varargsTest(int... args){
        int length = args.length;
        int sum = 0;
        for (int i: args){
            sum += i;
        }
        log.info("数组长度为：{}, 数组元素和为：{}", length, sum);
    }
}
